﻿<UserControl Name="i_UC" x:Class="UniversalEditor.Csv.TableContainer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             DataContext="{Binding RelativeSource={RelativeSource Self}}"
             d:DesignHeight="300" d:DesignWidth="300" >

    <UserControl.Resources>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="FontWeight" Value="Black" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="columnHeaderBorder" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                <EasingColorKeyFrame KeyTime="0" Value="Gray" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="columnHeaderBorder"
						        BorderThickness="1"
						        Padding="3,0,3,0">
                                <Border.BorderBrush>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Offset="0" Color="#A5A5A5" />
                                        <GradientStop Offset="1" Color="#4B4B4B" />
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Offset="0" Color="#FFF3F8F9" />
                                        <GradientStop Offset="1" Color="#FFA8E6F9" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
							                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
							                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type DataGridRowHeader}">
            <Setter Property="Width" Value="25" />
            <Setter Property="FontWeight" Value="Black" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="TooLow"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="RowHeaderBorder" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                <EasingColorKeyFrame KeyTime="0" Value="Gray" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="RowHeaderBorder"
						        BorderThickness="1"
						        Padding="3,0,3,0">

                                <Border.BorderBrush>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Offset="0" Color="#A5A5A5" />
                                        <GradientStop Offset="1" Color="#4B4B4B" />
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Offset="0" Color="#FFF3F8F9" />
                                        <GradientStop Offset="1" Color="#FFA8E6F9" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
							                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
							                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <DataGrid Name="i_CsvDG" LoadingRow="OnLoadingRow" ItemsSource="{Binding FieldsProperty}" 
                  HorizontalGridLinesBrush="DarkGray" VerticalGridLinesBrush="DarkGray"
                  HeadersVisibility="All" GridLinesVisibility="All"
                  AutoGenerateColumns="False" ColumnWidth="75" ColumnHeaderHeight="30" 
                  EnableRowVirtualization="True" EnableColumnVirtualization="True"
                  SelectionUnit="CellOrRowHeader" SelectionMode="Extended"
                  CanUserResizeColumns="True" CanUserReorderColumns="True" CanUserResizeRows="True"
                  ScrollViewer.CanContentScroll="True"
                  CellEditEnding="DataGrid_CellEditEnding" 
                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                  ScrollViewer.ScrollChanged="dtGrid_ScrollChanged" AutoGeneratingColumn="i_CsvDG_AutoGeneratingColumn" >
        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="LightGray"/>
                        <Setter Property="BorderBrush"  Value="LightGray"/>
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                    <Trigger Property="IsFocused"  Value="True">
                        <Setter Property="Background" Value="LightGray"/>
                        <Setter Property="BorderBrush" Value="LightGray"/>
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                    <Trigger Property="IsEditing" Value="True">
                        <Setter Property="Background" Value="LightGray"/>
                        <Setter Property="BorderBrush" Value="LightGray"/>
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGrid.CellStyle>
    </DataGrid>
</UserControl>
    
